<?php
if(isset($_GET['logout']) && ($_GET['logout']=="true")){
	session_start();
	session_destroy();
	header('Location:index.php');
} else{
	if(isset($_POST['email']) && isset($_POST['senha'])){
		require("conexao.php");
		$sql = mysql_query("SELECT * FROM usuario WHERE email = '".$_POST['email']."' AND senha = '".$_POST['senha']."'");
		if(mysql_num_rows($sql) > 0){
			$row = mysql_fetch_array($sql);
			session_start();
			$_SESSION['id'] = $row['id'];
			$_SESSION['email'] = $row['email'];
			header("Location: principal.php");
		} else{
			header('Location:index.php?error=1');
		}       
	}else {
		header('Location:index.php?error=1');
	} 
}
?>